﻿using AspDotNet.Framework.Mvc.FirstDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AspDotNet.Framework.Mvc.FirstDemo.Controllers
{
    public class StudentOperationController : BaseController
    {
        public ActionResult ShowStudents()
        {
            return View(Student.Students.OrderBy(p => p.ID).ToList());
        }

        public ActionResult Edit(int id)
        {
            return View(Student.Students.FirstOrDefault(p => p.ID == id));
        }

        [HttpPost]
        public ActionResult Edit(Student student)
        {
            var oldStudent = Student.Students.FirstOrDefault(p => p.ID == student.ID);
            Student.Students.Remove(oldStudent);
            Student.Students.Add(student);
            return RedirectToAction(nameof(ShowStudents));
        }
    }
}